package com.example.phone.home;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.phone.R;
import com.example.phone.search.SearchActivity;


public class HomeHeadFragment extends Fragment implements View.OnClickListener {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view =  inflater.inflate( R.layout.fragment_home_head, container, false );
        headClick( view );
        return view;
    }

    //获取控件
    private void headClick(View view) {
        ImageView iv_scan = view.findViewById( R.id.iv_scan );
        ImageView iv_search = view.findViewById( R.id.iv_search );
        //ImageView iv_car = view.findViewById( R.id.iv_car );

        iv_scan.setOnClickListener( this );
        iv_search.setOnClickListener( this );
        //iv_car.setOnClickListener( this );
    }

    //注册点击事件
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_scan:
                Toast.makeText( getActivity(), "二维码扫描", Toast.LENGTH_SHORT ).show();
                break;
            case R.id.iv_search:
                Toast.makeText( getActivity(), "搜索", Toast.LENGTH_SHORT ).show();
                Intent intent = new Intent(getActivity(), SearchActivity.class);
                startActivity(intent);
                break;
            //case R.id.iv_car:
            //    Toast.makeText( getActivity(), "购物车", Toast.LENGTH_SHORT ).show();
            //    break;
        }
    }
}
